<template>
	<div class="course">
		<Search @searchParent="searchParent" @resetParent="resetParent" />
		<List :arr="arr" @resetparentFun="getData" @openDialog="parentDialog" />
		<Pagination :total="total" :pageSize="pageSize" />
		<Dialog v-if="isShow" :row="row" />
	</div>
</template>

<script>
import Search from "./components/Search.vue";
import List from "./components/List.vue";
import Pagination from "./components/Pagination.vue";
import Dialog from "./components/Dialog.vue";
import { getCourse } from "../../api/course";
export default {
	data() {
		return {
			arr: [],
			isShow: false,
			page: 1,
			total: 0,
			pageSize: 8,
			search: "",
			row: {},
		};
	},
	components: {
		Search,
		List,
		Pagination,
		Dialog,
	},
	mounted() {
		this.getData();
	},
	methods: {
		// 搜索
		searchParent(val) {
			this.search = val;
			this.getData();
		},

		// 重置
		resetParent() {
			this.search = "";
			this.getData();
		},

		// 获取数据
		getData() {
			const params = {
				search: this.search,
				page: this.page,
				pageSize: this.pageSize,
			};
			getCourse(params).then((res) => {
				console.log("newList2", res);
				if (res.code == 200) {
					this.arr = res.data;
					this.total = res.total;
				}
			});
		},

		// 编辑
		parentDialog(val) {
			this.row = val;
			this.isShow = true;
		},
	},
};
</script>

<style lang="less" scoped>
</style>
